<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{% block title %} {% endblock %}</title>
    <link href="{{ url_for('static', filename='bootstrap.min.css') }}" rel="stylesheet">
    <link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
</head>
<body>
    <nav class="navbar navbar-expand-lg navbar-light bg-light">
        <div class="container-fluid">
            <a class="navbar-brand" href="/">Data-analysis-web-app</a>
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarSupportedContent">
                <ul class="navbar-nav me-auto mb-2 mb-lg-0">
                    {% if not login_none %}
                    <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle" href="#" id="navbarFileDropdownMenuLink" role="button" data-bs-toggle="dropdown" aria-expanded="false">
                            Файл
                        </a>
                        <ul class="dropdown-menu" aria-labelledby="navbarFileDropdownMenuLink">
                            <li><a class="dropdown-item" href="#" data-bs-toggle="modal" data-bs-target="#filesModal" onclick="getUserFiles()">Открыть</a></li>
                            {% if not data_none %}
                            <li><hr class="dropdown-divider"></li>
                            <li><a class="dropdown-item" href="#" onclick="saveFile(':')">Сохранить</a></li>
                            <li><a class="dropdown-item" href="#" onclick="saveFile('input')">Сохранить как ...</a></li>
                            <li><hr class="dropdown-divider"></li>
                            <li><a class="dropdown-item" href="./download_file">Экспортировать</a></li>
                            {% endif %}
                        </ul>
                    </li>
                    {% if not data_none %}
                    <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle" href="#" id="navbarProcessingDropdownMenuLink" role="button" data-bs-toggle="dropdown" aria-expanded="false">
                            Обработка
                        </a>
                        <ul class="dropdown-menu" aria-labelledby="navbarProcessingDropdownMenuLink">
                            <li><a class="dropdown-item" href="./table/auto_rename_columns">Автоматическое изменение имён столбцов</a></li>
                            <li><hr class="dropdown-divider"></li>
                            <li><a class="dropdown-item" href="#" onclick="deleteDuplicates(':')">Удаление дубликатов</a></li>
                        </ul>
                    </li>
                    <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle" href="#" id="navbarInfoDropdownMenuLink" role="button" data-bs-toggle="dropdown" aria-expanded="false">
                            Информация
                        </a>
                        <ul class="dropdown-menu" aria-labelledby="navbarInfoDropdownMenuLink">
                            <li><a class="dropdown-item" href="#" onclick="getTableInfo()">Общая информация</a></li>
                            <li><a class="dropdown-item" href="./table/profile_report" target="_blank">Подробная информация</a></li>
                            <li><hr class="dropdown-divider"></li>
                            <li><a class="dropdown-item" href="#" onclick="getTableSkips()">Количество пропусков</a></li>
                        </ul>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link active" data-bs-toggle="modal" data-bs-target="#graphModal" href="#">График</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link active" data-bs-toggle="modal" data-bs-target="#pivotTableModal" href="#">Сводная таблица</a>
                    </li>
                    {% endif %}
                    {% endif %}
                </ul>
                <div class="d-flex">
                    {% if login_none %}
                    <button class="btn btn-outline-primary me-2" data-bs-toggle="modal" data-bs-target="#loginModal" type="button" onclick="hideShow('registerForm', 'loginForm')">Авторизация</button>
                    <button class="btn btn-outline-primary me-2" data-bs-toggle="modal" data-bs-target="#loginModal" type="button" onclick="hideShow('loginForm', 'registerForm')">Регистрация</button>
                    {% endif %}
                    {% if not login_none %}
                    <div class="dropdown">
                        <a class="btn btn-primary dropdown-toggle" href="#" role="button" id="dropdownMenuLink" data-bs-toggle="dropdown" aria-expanded="false">
                            {{ login }}
                        </a>
                        <ul class="dropdown-menu dropdown-menu-end" aria-labelledby="dropdownMenuLink">
<!--                             <li><a class="dropdown-item" href="#">Настройки</a></li>
                            <li><hr class="dropdown-divider"></li> -->
                            <li><a class="dropdown-item" href="./logout">Выход</a></li>
                        </ul>
                    </div>
                    {% endif %}
                </div>
            </div>
        </div>
    </nav>
    {% block content %} {% endblock %}
    <div class="modal fade" id="loginModal" tabindex="-1" aria-labelledby="loginModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content" id="loginForm"">
                <div class="modal-header">
                <h5 class="modal-title" id="loginModalLabel">Авторизация</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Закрыть"></button>
                </div>
                <div class="modal-body">
                    <form>
                        <div class="form-group mb-3">
                            <label for="inputLogin">Логин</label>
                            <input type="text" class="form-control" id="inputLogin" aria-describedby="loginHelp" placeholder="Введите логин">
                        </div>
                        <div class="form-group mb-3">
                            <label for="inputPassword">Пароль</label>
                            <input type="password" class="form-control" id="inputPassword" placeholder="Введите пароль">
                        </div>
                        <span>Нет аккаунта? <a href="#" onclick="hideShow('loginForm', 'registerForm')">Регистрация</a></span>
                    </form>
                </div>
                <div class="modal-footer">
                <button type="button" class="btn btn-danger" data-bs-dismiss="modal">Закрыть</button>
                <button onclick="login()" type="button" class="btn btn-primary">Авторизация</button>
                </div>
            </div>
            <div class="modal-content" id="registerForm"">
                <div class="modal-header">
                    <h5 class="modal-title" id="loginModalLabel">Регистрация</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Закрыть"></button>
                </div>
                <form action="" method="post">
                    <div class="modal-body">
                        <div class="form-group mb-3">
                            <label for="inputRegisterLogin">Логин</label>
                            <input type="text" class="form-control" id="inputRegisterLogin" aria-describedby="loginHelp" placeholder="Введите логин" onchange="checkLogin(this.value);">
                            <div id="invalidLogin" class="invalid-feedback">
                                Такой логин уже существует.
                            </div>
                        </div>
                        <div class="form-group mb-3">
                            <label for="inputRegisterPassword">Пароль</label>
                            <input type="password" class="form-control" id="inputRegisterPassword" placeholder="Введите пароль" onchange="checkPassword();">
                        </div>
                        <div class="form-group mb-3">
                            <label for="inputRepeatPassword">Повторите пароль</label>
                            <input type="password" class="form-control" id="inputRepeatPassword" placeholder="Повторно введите пароль" onchange="checkPassword();">
                            <div id="invalidPassword" class="invalid-feedback">
                                Пароли не совпадают.
                            </div>
                        </div>
                        <span>Есть аккаунт? <a href="#" onclick="hideShow('registerForm', 'loginForm')">Войти</a></span>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-danger" data-bs-dismiss="modal">Закрыть</button>
                        <button onclick="addAccount()" type="button" class="btn btn-primary">Регистрация</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
    {% if not login_none %}
    <div class="modal fade" id="filesModal" tabindex="-1" aria-labelledby="filesModalLabel" aria-hidden="true">
        <div class="modal-dialog modal-dialog-scrollable">
        <div class="modal-content">
            <div class="modal-header">
            <h5 class="modal-title" id="exampleModalLabel">Файлы</h5>
            <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div id="filesWindow" class="modal-body files-window">
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-danger" data-bs-dismiss="modal">Закрыть</button>
                <button type="button" class="btn btn-primary" onclick="getUserFiles()">Обновить</button>
                <label class="btn btn-primary" for="userFile">Загрузить файл</label>
                <input name="userFile" id="userFile" type="file" style="display: none;" onchange="uploadFile(this.files)">
                <button type="button" class="btn btn-primary" onclick="deleteFile()">Удалить</button>
            </div>
        </div>
        </div>
    </div>
    {% if not data_none %}
    <div class="modal fade" id="infoModal" tabindex="-1" aria-labelledby="infoModalLabel" aria-hidden="true">
        <div class="modal-dialog modal-dialog-scrollable">
        <div class="modal-content">
            <div class="modal-header">
            <h5 class="modal-title" id="infoModalLabel">Инфо</h5>
            <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div id="infoWindow" class="modal-body">
                <samp id="infoText"></samp>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-danger" data-bs-dismiss="modal">Закрыть</button>
            </div>
        </div>
        </div>
    </div>
    <div class="modal fade" id="graphModal" tabindex="-1" aria-labelledby="graphModalLabel" aria-hidden="true">
        <div class="modal-dialog modal-dialog-scrollable">
        <div class="modal-content">
            <div class="modal-header">
            <h5 class="modal-title" id="graphModalLabel">Построить график</h5>
            <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <form action="/graph" method="post" target="_blank">
            <div class="modal-body">
                <div class="mb-3">
                    <label for="graphName" class="form-label">Название графика</label>
                    <input type="text" class="form-control" id="graphName" name="graphName">
                </div>
                <div class="mb-3">
                    <label for="graphType" class="form-label">Вид графика</label>
                    <select name="graphType" id="graphType" class="form-select">
                        <option value="scatter">График разброса</option>
                        <option value="bar">Столбчатый график</option>
                        <option value="line">Линейный график</option>
                    </select>
                </div>
                <div class="mb-3">
                    <label for="xGraph" class="form-label">X</label>
                    <select name="xGraph" id="xGraph" class="form-select">
                        {%for i in range(0, len)%}
                            <option>{{data.columns[i]}}</option>
                        {%endfor%}
                    </select>
                </div>
                <div class="mb-3">
                    <div class="mb-3">
                        <label for="yGraph" class="form-label">Y</label>
                        <select name="yGraph" id="yGraph" class="form-select">
                            {%for i in range(0, len)%}
                                <option>{{data.columns[i]}}</option>
                            {%endfor%}
                        </select>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-danger" data-bs-dismiss="modal">Закрыть</button>
                <button type="submit" class="btn btn-primary">Построить график</button>
            </div>
            </form>
        </div>
        </div>
    </div>
    <div class="modal fade" id="replaceModal" tabindex="-1" aria-labelledby="replaceModalLabel" aria-hidden="true">
        <div class="modal-dialog modal-dialog-scrollable">
        <div class="modal-content">
            <div class="modal-header">
            <h5 class="modal-title" id="replaceModalLabel"></h5>
            <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <form action="./table/replace_values" method="post">
            <div class="modal-body">
                <div class="mb-3">
                    <label for="findValue" class="form-label">Найти</label>
                    <input type="text" class="form-control" id="findValue" name="findValue">
                </div>
                <div class="mb-3">
                    <label for="replaceValue" class="form-label">Заменить</label>
                    <input type="text" class="form-control" id="replaceValue" name="replaceValue">
                </div>
                <input type="text" id="columnReplace" name="columnReplace" style="display: none;">
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-danger" data-bs-dismiss="modal">Закрыть</button>
                <button type="submit" class="btn btn-primary">Заменить значения</button>
            </div>
            </form>
        </div>
        </div>
    </div>
    <div class="modal fade" id="pivotTableModal" tabindex="-1" aria-labelledby="pivotTableModalLabel" aria-hidden="true">
        <div class="modal-dialog modal-dialog-scrollable">
        <div class="modal-content">
            <div class="modal-header">
            <h5 class="modal-title" id="pivotTableModalLabel">Создать сводную таблицу</h5>
            <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <form action="./table/create_pivot_table" method="post">
            <div class="modal-body">
                <div class="mb-3">
                    <label for="pivotTableIndex" class="form-label">Индекс</label>
                    <select name="pivotTableIndex" id="pivotTableIndex" class="form-select">
                        {%for i in range(0, len)%}
                            <option>{{data.columns[i]}}</option>
                        {%endfor%}
                    </select>
                </div>
                <div class="mb-3">
                    <label for="pivotTableValues" class="form-label">Столбец</label>
                    <select name="pivotTableValues" id="pivotTableValues" class="form-select">
                        {%for i in range(0, len)%}
                            <option>{{data.columns[i]}}</option>
                        {%endfor%}
                    </select>
                </div>
                <div class="mb-3">
                    <label for="pivotTableFunction" class="form-label">Функция</label>
                    <select name="pivotTableFunction" id="pivotTableFunction" class="form-select">
                            <option value="mean">Найти среднее</option>
                            <option value="median">Найти медиану</option>
                    </select>
                </div>
                <div class="mb-3">
                    <label for="pivotTableSaveName" class="form-label">Имя файла</label>
                    <input type="text" class="form-control" id="pivotTableSaveName" name="pivotTableSaveName">
                </div>
                <div class="mb-3 form-check">
                    <input type="checkbox" class="form-check-input" id="pivotTableOpen" name="pivotTableOpen">
                    <label class="form-check-label" for="pivotTableOpen">Открыть таблицу после создания</label>
                </div>
                <input type="text" id="columnReplace" name="columnReplace" style="display: none;">
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-danger" data-bs-dismiss="modal">Закрыть</button>
                <button type="submit" class="btn btn-primary">Создать таблицу</button>
            </div>
            </form>
        </div>
        </div>
    </div>
    {% endif %}
    {% endif %}
    <div id="context-menu" class="dropdown-menu context-menu" aria-labelledby="ctx-menu"></div>
    <script src="{{ url_for('static', filename='bootstrap.bundle.min.js') }}"></script>
    <script src="{{ url_for('static', filename='script.js') }}"></script>
</body>
</html>
